package com.ht.medicaltreatment.viewmodel

import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.api.ConsumableSampleBoxAPI
import com.ht.medicaltreatment.api.ConsumableSampleBoxBindingAPI
import com.ht.medicaltreatment.bean.PrepareConsumableFileBean
import com.ht.medicaltreatment.bean.PrepareData

class BindingConsumableViewModel : BaseViewModel() {
    fun requestList(id:Int,onSuccess:(MutableList<PrepareData>)->Unit){
        EasyHttp.post(this)
            .api(ConsumableSampleBoxAPI("$id"))
            .request(object : OnHttpListener<PrepareConsumableFileBean>{
                override fun onHttpSuccess(result: PrepareConsumableFileBean) {
                    if(result.code == 200){
                        onSuccess(result.data)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"请求错误")
                }

            })
    }

    fun bindding(rfidCode:String,batchentrySampleBoxId:String,sampleBoxStruId:String,onSuccess:(MutableList<PrepareData>)->Unit){
        EasyHttp.post(this)
            .api(ConsumableSampleBoxBindingAPI(batchentrySampleBoxId,rfidCode,sampleBoxStruId))
            .request(object : OnHttpListener<PrepareConsumableFileBean>{
                override fun onHttpSuccess(result: PrepareConsumableFileBean) {
                    if(result.code == 200){
                        onSuccess(result.data)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"请求错误")
                }

            })
    }
}
